package org.zw.android.framework.app;

import org.zw.android.framework.impl.FrameworkFacade;

import android.app.Application;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.util.DisplayMetrics;
import android.view.WindowManager;

/**
 * Application 上下文
 * 
 * @author zhouwei
 *
 */
public class AppApplication extends Application {
	
	private static AppApplication _instance ;
	
	@Override
	public void onCreate() {
		super.onCreate();
		
		// screen width & height
		WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
		DisplayMetrics mDisplayMetrics = new DisplayMetrics();
		wm.getDefaultDisplay().getMetrics(mDisplayMetrics);

		// screen
		AppConfig.SCREEN_WIDTH  = mDisplayMetrics.widthPixels;
		AppConfig.SCREEN_HEIGHT = mDisplayMetrics.heightPixels;
		
		// preferences
		AppPreferences.initPreferences(this);
		
		// framework facade
		FrameworkFacade.create(this);
		
		// resource
		AppResourceUtil.initResource(this);
		
		_instance = this ;
	}
	
	public static AppApplication getInstance(){
		return _instance ;
	}
	
	public static String getVersionName(){
		
		try{
			PackageManager packageManager = _instance.getPackageManager();
			PackageInfo packInfo = packageManager.getPackageInfo(_instance.getPackageName(),0);
			return packInfo.versionName;
		} catch(Exception e){
			e.printStackTrace() ;
		}
		
		return "0.0.1" ;
	}
}
